<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>动态表单</title>
    
	<%@ include file="/main/main_css.jsp" %>
    <%@ include file="/main/main_js.jsp" %>
   	<script src="static/plugins/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="static/plugins/jquery.jqprint-0.3.js" type="text/javascript"></script>
    <script src="JS/main.js"></script>
     <script src="JS/A4Print.js"></script>
    <script src="JS/main.js"></script>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
	<style>
	
	.icheckbox_square-blue {
	    background-position: -24px 0;
	}
	.print-btn{
		width: 100px;
	    height: 40px;
	}
	.footer {
    background-color: #cad5f3;
    height: 98px;
    padding: 0 20px;
}
	</style>
  </head>
  
  <body>
    <!--  -->
    <div class="all-wrapper">
        <div class="row com-header text-center">
            <span>鹰潭市行政服务中心</span>
        </div>
       
        <div class="row main-content time-table ">
        	<div class="row" >
        		<a class="btn btn-success btn-lg hidden" href="loginOut" role="button" style="margin-top:16px;"><i class="fa fa-reply"></i>返回首页</a>
                <div class="time-count pull-right">
                   <span>剩余</span> <span id="time" class="text-red"></span> <span>秒</span>
                </div>
            </div>
            <div class="col-md-24">
                <h1>${itemName }</h1>
            </div>
            <div class="row">
            	<button class="btn btn-warning btn-lg print-btn" type="button" onclick="aa()">打印</button>
            </div>
            <div class="row to-takephoto">
           	 <a href="dynamicfile?itemId=${itemId }&prokeyid=${prokeyid}">
            	<div class="image-wrapper">
            		<img src="static/image/index/dform_icon_camera.png">
            	</div>
            	<span class="teaser">	点击进入拍照页面</span>
             </a>
            </div>
            <div id="print" class="hidden">
        	<div class="col-md-24">
                <h1 align="center">${itemName }</h1>
            </div>
            <form action="saveitemdynamic" method="post" id="form">
            <table class="table table-bordered time-table-com" border="1" cellspacing="0" bordercolor="#000000" style="border:1px solid #efefef;">
                <tbody>
                    <tr>
                	<c:forEach var="dynamic" items="${commonList }" varStatus="i">
                		<td style="width:10%" class="x">
                            <span>
                            	<c:if test="${dynamic.style_id eq '005004' || dynamic.style_id eq '005002' }">
                            		${dynamic.field_cname }(单选)
                            	</c:if>
                            	<c:if test="${dynamic.style_id eq '005003'}">
                            		${dynamic.field_cname }(多选)
                            	</c:if>
                            	<c:if test="${dynamic.style_id != '005003' && dynamic.style_id != '005004' && dynamic.style_id != '005002'}">
                            		${dynamic.field_cname }
                            	</c:if>
                            </span>
                        </td>
                        <td style="width:10%" <c:if test="${(dynamic.style_id eq '005003') or (dynamic.style_id eq '005002') }">colspan='5'</c:if>>
                        	<!-- 普通文本 -->
                            <c:if test="${dynamic.style_id eq '002001' }"><!-- 普通文本 -->
	                            <c:if test="${dynamic.is_null eq '0' }"><!-- 判断是否为空 -->
		                            <c:if test="${empty dynamic.field_length or dynamic.field_length eq '' }"><!-- 判断是否限制输入长度 -->
		                            </c:if>
		                            <c:if test="${!empty dynamic.field_length or dynamic.field_length ne '' }">
		                            </c:if>
		                        </c:if>
		                        <c:if test="${dynamic.is_null eq '1' }">
		                            <c:if test="${empty dynamic.field_length or dynamic.field_length eq '' }">
		                            </c:if>
		                            <c:if test="${!empty dynamic.field_length or dynamic.FIELD_LENGTH ne '' }">
		                            </c:if>
	                            </c:if>
	                            <c:if test="${commonList[i.index+1].style_id eq '005002' or commonList[i.index+1].style_id eq '005003'}">
	                            	</tr><tr>
	                            </c:if>
                            </c:if>
                            <!-- 密码框 -->
                            <c:if test="${dynamic.style_id eq '002002' }"><!-- 密码框 -->
	                            <c:if test="${dynamic.is_null eq '0' }"><!-- 判断是否为空 -->
		                            <c:if test="${empty dynamic.field_length or dynamic.field_length eq '' }"><!-- 判断是否限制输入长度 -->
		                            </c:if>
		                            <c:if test="${!empty dynamic.field_length or dynamic.field_length ne '' }">
		                            </c:if>
		                        </c:if>
		                        <c:if test="${dynamic.is_null eq '1' }">
		                            <c:if test="${empty dynamic.field_length or dynamic.field_length eq '' }">
		                            </c:if>
		                            <c:if test="${!empty dynamic.field_length or dynamic.FIELD_LENGTH ne '' }">
		                            </c:if>
	                            </c:if>
	                            <c:if test="${commonList[i.index+1].style_id eq '005002' or commonList[i.index+1].style_id eq '005003'}">
	                            	</tr><tr>
	                            </c:if>
                            </c:if>
                            <!-- 大文本 -->
                            <c:if test="${dynamic.style_id eq '002004' }"><!-- 大文本 -->
	                            <c:if test="${dynamic.is_null eq '0' }"><!-- 判断是否为空 -->
		                            <c:if test="${empty dynamic.field_length or dynamic.field_length eq '' }"><!-- 判断是否限制输入长度 -->
	                            		<textarea class="form-control" rows="3" id="${dynamic.field_ename }" name="${dynamic.field_ename }" check-type="required" required-message="\u6b64\u9879\u4e0d\u80fd\u4e3a\u7a7a\uff01">${dynamic.default_value }</textarea>
		                            </c:if>
		                            <c:if test="${!empty dynamic.field_length or dynamic.field_length ne '' }">
		                            	<textarea class="form-control" rows="3" id="${dynamic.field_ename }" name="${dynamic.field_ename }" check-type="required" required-message="\u6b64\u9879\u4e0d\u80fd\u4e3a\u7a7a\uff01" maxlength="${dynamic.field_length }">${dynamic.default_value }</textarea>
		                            </c:if>
		                        </c:if>
		                        <c:if test="${dynamic.is_null eq '1' }">
		                            <c:if test="${empty dynamic.field_length or dynamic.field_length eq '' }">
		                            	<textarea class="form-control" rows="3" id="${dynamic.field_ename }" name="${dynamic.field_ename }">${dynamic.default_value }</textarea>
		                            </c:if>
		                            <c:if test="${!empty dynamic.field_length or dynamic.FIELD_LENGTH ne '' }">
		                            	<textarea class="form-control" rows="3" id="${dynamic.field_ename }" name="${dynamic.field_ename }" maxlength="${dynamic.field_length }">${dynamic.default_value }</textarea>
		                            </c:if>
	                            </c:if>
	                            <c:if test="${commonList[i.index+1].style_id eq '005002' or commonList[i.index+1].style_id eq '005003'}">
	                            	</tr><tr>
	                            </c:if>
                            </c:if>
                            <!-- 文件上传框 -->
                            <c:if test="${dynamic.style_id eq '002005' }"><!-- 文件上传框 -->
	                            <c:if test="${dynamic.is_null eq '0' }"><!-- 判断是否为空 -->
		                            <c:if test="${empty dynamic.field_length or dynamic.field_length eq '' }"><!-- 判断是否限制输入长度 -->
		                           		<input class="form-control input-lg" type="text" id="${dynamic.field_ename }" name="${dynamic.field_ename }" value="${dynamic.default_value }"/>
		                            </c:if>
		                            <c:if test="${!empty dynamic.field_length or dynamic.field_length ne '' }">
		                            	<input class="form-control input-lg" type="text" id="${dynamic.field_ename }" name="${dynamic.field_ename }" maxlength="${dynamic.field_length }" value="${dynamic.default_value }"/>
		                            </c:if>
		                        </c:if>
		                        <c:if test="${dynamic.is_null eq '1' }">
		                            <c:if test="${empty dynamic.field_length or dynamic.field_length eq '' }">
		                            	<input class="form-control input-lg" type="text" id="${dynamic.field_ename }" name="${dynamic.field_ename }" value="${dynamic.default_value }" />
		                            </c:if>
		                            <c:if test="${!empty dynamic.field_length or dynamic.FIELD_LENGTH ne '' }">
		                            	<input class="form-control input-lg" type="text" id="${dynamic.field_ename }" name="${dynamic.field_ename }" maxlength="${dynamic.field_length }" value="${dynamic.default_value }" />
		                            </c:if>
	                            </c:if>
	                            <c:if test="${commonList[i.index+1].style_id eq '005002' or commonList[i.index+1].style_id eq '005003'}">
	                            	</tr><tr>
	                            </c:if>
                            </c:if>
                            <!-- 日期框 -->
                            <c:if test="${dynamic.style_id eq '002006' }"><!-- 日期框 -->
	                            <c:if test="${dynamic.is_null eq '0' }"><!-- 判断是否为空 -->
		                            <c:if test="${empty dynamic.field_length or dynamic.field_length eq '' }"><!-- 判断是否限制输入长度 -->
		                           		<input class="form-control input-lg" type="text" id="${dynamic.field_ename }" name="${dynamic.field_ename }"  value="${dynamic.default_value }"/>
		                            </c:if>
		                            <c:if test="${!empty dynamic.field_length or dynamic.field_length ne '' }">
		                            	<input class="form-control input-lg" type="text" id="${dynamic.field_ename }" name="${dynamic.field_ename }"  maxlength="${dynamic.field_length }" value="${dynamic.default_value }"/>
		                            </c:if>
		                        </c:if>
		                        <c:if test="${dynamic.is_null eq '1' }">
		                            <c:if test="${empty dynamic.field_length or dynamic.field_length eq '' }">
		                            	<input class="form-control input-lg" type="text" id="${dynamic.field_ename }" name="${dynamic.field_ename }" value="${dynamic.default_value }" />
		                            </c:if>
		                            <c:if test="${!empty dynamic.field_length or dynamic.FIELD_LENGTH ne '' }">
		                            	<input class="form-control input-lg" type="text" id="${dynamic.field_ename }" name="${dynamic.field_ename }" maxlength="${dynamic.field_length }" value="${dynamic.default_value }" />
		                            </c:if>
	                            </c:if>
	                            <c:if test="${commonList[i.index+1].style_id eq '005002' or commonList[i.index+1].style_id eq '005003'}">
	                            	</tr><tr>
	                            </c:if>
                            </c:if>
                           <!-- 单选 -->
                            <c:if test="${dynamic.style_id eq '005002'}">
	                            <c:forEach  var="source" items="${dynamic.sourceList}" varStatus="j">
			                    	<label class="radio-inline" style="margin-top: 10px;">
	                            		<input type="radio" name="${dynamic.field_ename }" id="${dynamic.field_ename }${j.count  }" value="${source.s_id }"> ${source.s_val }
		                            </label>
	                         	</c:forEach>
	                         	</td></tr>
                            </c:if>
                            <!-- 多选 -->
                            <c:if test="${dynamic.style_id eq '005003' }"><!-- 多选 -->
                            	<input type="hidden" name="${dynamic.field_ename }" id="${dynamic.field_ename }" />
	                            <c:forEach  var="source" items="${dynamic.sourceList}" varStatus="j">
	                            	<label class="checkbox-inline" style="margin-top: 10px;" >
	                            		<input type="checkbox" name="${dynamic.field_ename }${j.count  }" ename='${dynamic.field_ename }' id="${dynamic.field_ename }${j.count  }" value="${source.s_id }"> ${source.s_val }
	                            	</label>
	                            </c:forEach>
	                            </td></tr>
                            </c:if>
                            <!-- 下拉 -->
                            <c:if test="${dynamic.style_id eq '005004' }"><!-- 下拉 -->
	                            <div class="col-md-15">
		                            	<c:forEach  var="source" items="${dynamic.sourceList}" varStatus="j">
		                            		<input type="checkbox" name="${dynamic.field_ename }" id="${dynamic.field_ename }${j.count  }" value="${source.s_id }"> ${source.s_val }
		                            	</c:forEach>
                                </div>
                                <c:if test="${commonList[i.index+1].style_id eq '005002' or commonList[i.index+1].style_id eq '005003'}">
	                            	</tr><tr>
	                            </c:if>
                            </c:if>
                        </td>
                        <!-- 一行存在4列则换行 -->
                        <c:if test="${(i.count%3 == 0 or i.count/3 == 1) and dynamic.style_id ne '005003' and dynamic.style_id ne '005002' }"></tr><tr></c:if>
                    </c:forEach>
                    </tr>
                </tbody>
                <c:forEach var="h" items="${hiddenList}" varStatus="j">
                	<input type="hidden" id="${h.field_ename }" name="${h.field_ename }" value="${h.default_value }"/>
                </c:forEach>
            </table>
            <input name="itemId"  type="hidden"   value="${itemId }">
            <input name="prokeyid" type="hidden" value="${prokeyid }">
            <input name="table_ename" type="hidden" value="${list[0].table_ename }">
            </form></div>
        </div>
        <div class="row footer">
            <!-- <a class="btn btn-primary btn-lg" href="javascript:history.go(-1)" role="button"><i class="fa fa-arrow-left"></i>上一步</a>
            <button class="btn btn-primary btn-lg" onclick="submit()" role="button">提交<i class="fa fa-hand-pointer-o"></i></button> -->
             <a class="btn btn-success btn-lg" href="loginOut" role="button"><i class="fa fa-reply"></i>返回首页</a>
            <a class="btn btn-primary btn-lg" href="javascript:history.go(-1)" role="button"><i class="fa fa-arrow-left"></i>上一步</a>
        </div>
        <form id="loginOut" action="loginOut"></form>
        <script>
      	
		var tdlength = $('.time-table-com').find('tr').eq(4).find('td').length;
	      if(tdlength=='2'){
	    	  
	    	  $('.time-table-com').find('tr').eq(4).find('td:last').attr('colspan','5');
	      }
        function aa(){
        	var str = $("#print").html();
        	$("#print").removeClass('hidden');
        	printHtmlA4(str);
        	//$("#print").jqprint();
        	$("#print").addClass('hidden');
        }
        
        function printHtmlA4(test){
       	   	    send_command(
      	        "printhtml",
      	      	test,
      	        function (json) {
      	            
      	        }); 
       	   	var index = layer.load(3, {
			    shade: [0.3,'#000'] //0.1透明度的白色背景  
				});
		   layer.msg('文件打印中,请稍等片刻......', {time:3000}); 
				setTimeout(function(){
				    layer.close(index);
			},3000);
      	}
      	//倒计时
    	var count =  119;
    	function countdown(){
    		$("#time").text(count);
    		if(count > 0){
    			window.setTimeout("countdown()",1000);
    			count --;
    		}else{
    			$("#loginOut").submit();
    		}
    	}
    	countdown();
        
        
	       /*  $('.checkbox-inline input').iCheck({
	            checkboxClass: 'icheckbox_square-blue',
	            radioClass: 'iradio_square-blue',
	            increaseArea: '20%'// optional
	        });
	        $('.radio-inline input').iCheck({
	            checkboxClass: 'icheckbox_square-blue',
	            radioClass: 'iradio_square-blue',
	            increaseArea: '20%' // optional
	        });
	         */
	        function submit(){
	        	$("input[type='checkbox']").each(function(index,Element){
	        		if($(Element).is(":checked")){
	        			var name = $(Element).attr("ename");
	        			var vals = $("#"+name).val();
	        			if(vals==""){
	        				vals = $(Element).val();
	        			}else{
	        				vals = $("#"+name).val()+","+$(Element).val();
	        			}
	        			$("#"+name).val(vals);
	        		}
	        	});
	        	$("#form").submit();
	        }
	        var winH = $(document).height();
	        var mainH = winH -180;
	        $('.main-content').height(mainH);
	        $('.all-wrapper').slimScroll({
	            height: '900px',
			size: '15px',
			alwaysVisible: true,
			disableFadeOut: false,
			railVisible: true
	        });
	     	$('input[type="text"]').each(function(index,el){
		        var id_ = $(el).attr('id');	
		        console.log($(this));
		        console.log(id_);
		        $("#"+id_).on('click',function (){
		        	
		    		var info = $("#"+id_).val();
		    	    var test = { 'info': info, 'ispassword': 0 };
		    	    var data = JSON.stringify(test);
		    	    send_command(
		    	        "imewrite", data,
		    	        function (receivedData) {
		    	            var data = JSON.parse(receivedData);
		    	            $("#"+id_).val(data.msg);
		    	        }
		    	    ); 
		    	});
	        });
	     	var winH = $(document).height();
	        var mainH = winH - 160;
	        $('.main-content').height(mainH);
        </script>
  </body>
</html>
